
public class FormalParam {

	public DataInfo dataInfo;
	
	private String name;
	private String type;
	
	public FormalParam(String name, String type, DataInfo dataInfo){
		
		this.name = name;
		this.type = type;
		this.dataInfo = dataInfo;
		
	}
	
	public String toString(){
		
		String result = "Formal Param "+name+"\n";
		
		return result;
		
	}

	public void check() throws SemanticException {
		
		SymbolTable st = SymbolTable.getInstance();
		
		if(st.contains(name))
		{
			String details ="The identifier "+name+" is already defined."; 
			if( dataInfo != null )
				throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
			else
				throw new SemanticException( details );
			
		}
		
		st.add(new Entry(name, "FormalParam", type));
		
	}
	
	public String getType(){
		
		return(type);
		
	}
	
}
